// 加密相关的实验

package lab

import (
    "fmt"
    "time"
    "strings"

    "tokyo/core"
)


// 生成明文和密文
func CreateDark(briLen int) string {
    brightText := core.GetRandStr()
    darkText := core.GetHashCode(brightText)
    fmt.Println("原始明文：", brightText)
    fmt.Println("原始SHA256：", darkText)
    fmt.Println(strings.Repeat("-", 50))
    return darkText
}

// 破解密文
func BreakDark(briLen int, darkText string)  {
    var tryBright string
    var tryDark string
    decodeStart := time.Now()
    decodeCount := 0
    for {
        tryBright = core.GetRandStr()
        tryDark = core.GetHashCode(tryBright)
        decodeCount += 1
        if (tryDark == darkText) {
            break
        }
    }
    timeCost := time.Since(decodeStart)

    fmt.Println("破解明文：", tryBright)
    fmt.Println("破解SHA256：", tryDark)
    fmt.Println("破解次数：", decodeCount)
    fmt.Println("破解时间：", timeCost)
    fmt.Println(strings.Repeat("-", 50))
}
